import type { ResponseType } from '@/api/common/type';
import request from '@/utils/request';
import type { AttrForm, Category } from './type';
enum API {
	NEXT_LEVEL_CATEGORY_URL = '/admin/product/nextLevelCategory',
	GET_ATTR_URL = '/admin/product/getAttr',
	SAVE_ATTR_URL = '/admin/product/saveAttrInfo',
	UPDATE_ATTR_URL = '/admin/product/updateAttrInfo',
	DELETE_ATTR_URL = '/admin/product/deleteAttrInfo'
}

/**
 * 根据属性id获取下级属性列表
 * @param id 属性id
 * @returns promise
 */
export const reqGetNextLevelCategory = (id: number = 0): Promise<ResponseType<Category>> => {
	return request.get(API.NEXT_LEVEL_CATEGORY_URL + `/${id}`);
};

/**
 * 根据属性id获取下级属性列表
 * @param id 属性id
 * @returns promise
 */
export const reqGetAttr = (id: number = 0): Promise<ResponseType<Attr[]>> => {
	return request.get(API.GET_ATTR_URL + `/${id}`);
};
/**
 * 保存分类的属性信息
 * @param attrForm form
 * @returns
 */
export const reqSaveAttrInfo = (attrForm: AttrForm): Promise<ResponseType<any>> => {
	return request.post(API.SAVE_ATTR_URL, attrForm);
};
/**
 * 更新属性的信息
 * @param attrForm form
 * @returns
 */
export const reqUpdateAttrInfo = (attrForm: AttrForm): Promise<ResponseType<any>> => {
	return request.put(API.UPDATE_ATTR_URL, attrForm);
};

/**
 * 更新属性
 * @param id 需要删除的属性id
 * @returns
 */
export const reqDeleteAttrInfo = (id: number): Promise<ResponseType<any>> => {
	return request.delete(API.DELETE_ATTR_URL + `/${id}`);
};
